package com.example.smartcity_poverty.ui.AllService.VolunteerService.ui.Me

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.ui.AllService.VolunteerService.fragment.VtMeTabViewFragment
import com.example.smartcity_poverty.ui.AllService.VolunteerService.fragment.VtMeTabViewFragment.Companion.vtMeId
import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.android.synthetic.main.fragment_vts_me.*

/**
 * 志愿服务我的服务
 */
class VtsMeFragment : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_vts_me, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val tab = vtMeTabLayout
        val vp = vtMeViewPager2

        vp.adapter = object : FragmentStateAdapter(this) {
            override fun getItemCount(): Int = 3

            override fun createFragment(position: Int): Fragment = when (position) {
                0 -> VtMeTabViewFragment()
                1 -> VtMeTabViewFragment()
                else -> VtMeTabViewFragment()
            }

            override fun getItemId(position: Int): Long {
                vtMeId = when (position) {
                    0 -> 10
                    1 -> 20
                    else -> 30
                }
                return super.getItemId(position)
            }
        }

        TabLayoutMediator(tab, vp) { tab1, position ->
            when (position) {
                0 -> tab1.text = "已完成"
                1 -> tab1.text = "已报名"
                else -> tab1.text = "已取消"
            }
        }.attach()
    }
}